/*
 * @Author: your name
 * @Date: 2020-06-01 14:58:54
 * @LastEditTime: 2020-06-03 15:07:46
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \X\1km\agv\upper.h
 */ 
/*
upper.h
offer upper api
designed by lunanting

---------------------------
2020-05-22 16:58:22
create file
---------------------------
*/
#ifndef __UPPER_H
#define __UPPER_H

#include "../../include/aos/hal/uart.h"
#include "../bsp/base_type.h"
#include"../driver/driver.h"
#include "mag_navigation.h"
#include"string.h"
#include <stdlib.h>
#include "stringdef.h"

#define __FILENAMEUP__ (strrchr(__FILE__,'/') ? strrchr(__FILE__,'/') + 1 : __FILE__)
#define UPPER_LOG(format, args...) printf("[%s][%s][%d]: "format"\r\n",__FILENAMEUP__,__func__,__LINE__,##args)

/*******************data type define*******************/

//set agv state type
typedef enum{
    upper_agv_serch_car=0,    //serch car，找车
    upper_agv_against_car,    //贴行
    upper_agv_back_home,      //回待机位
    upper_agv_mag_drive,      //磁导航行车
    upper_agv_stop=10,        //结束当前模式
    upper_agv_pause,          //暂停动作
    upper_agv_continue,       //继续当前模式
}UPPER_AGV_set;


//agv state
typedef struct{
    u8 move_mode;    //agv move mode
    u8 move_state;   //agv state  等于7代表静止时震动
    u8 power;        //agv power 电量
    u8 stoped;       //agv stoped 障碍物，1=有
    u8 l_wheel_error;   //左轮即正面车轮异常状态值，0=normal,255=comm error,1~254:motor error
    u8 r_wheel_error;   //右轮即背面车轮异常状态值，0=normal,255=comm error,1~254:motor error
    u8 mag_error;       //0=normal,255=comm error,1~254:sensor error
    u8 rfid_error;      //0=normal,255=comm error,1~254:sensor error
    u8 v_lidar_error;   //竖向激光雷达异常状态值，0=normal,255=comm error,1~254:sensor error
    u8 h_lidar_error;   //横向激光雷达异常状态值，0=normal,255=comm error,1~254:sensor error
    u8 gyro_error;      //陀螺仪异常状态值，0=normal,255=comm error,1~254:sensor error
    u8 navi_error;      //导航运动异常状态值，0=normal,1~254:error
    u8 too_near;        //侧向过近，1=有
    float angle;        //机器人th坐标，单位1/1000度
    float locate_x;     //机器人X坐标，单位mm
    float locate_y;     //机器人Y坐标，单位mm
    int hight;          //雷达测量高度值，相对于雷达安装面(750mm处)的高度，有可能是负数，单位mm
    int dist;           //雷达测量距离值，单位mm
}UPPER_AGV_state;

//upper class
typedef struct{
    u8 init;    //init state
    u8 agv_mode;    //agv mode
    u8 agv_state;   //agv state
    u8 online;  //online state 1=online
    uart_dev_t uart;    //uart object
    UPPER_AGV_state agv;    //agv 
}UPPER_AGV_class;




/************************extern function***********************/
#ifndef WASHER_MERGE
extern int xp_agv_upper_init(u8 port,int speed);    //upper connect init
#else
extern int xp_agv_upper_init();           //upper connect init
#endif
extern void xp_upper_send(char *data);    //send data to upper
extern void xp_upper_stoped_set(u8 sta);    //set agv stoped state
extern void xp_upper_analysis(const char *data,u32 len);    //upper recive data analysis
extern int xp_upper_user_api(const char *data,u32 len); //define user upper response api
extern UPPER_AGV_class* get_return_upper_hander(void);
extern void xp_upper_set_robot_pose(double angle,double location_x,double location_y);
extern void xp_upper_move_sate_set(u8 sta);
extern void xp_upper_lidar_state_set(u8 sta);
extern int xp_upper_get_agv_state(UPPER_AGV_state *p_agv_state);
extern int xp_upper_debug(char *type,char *fun,char *param);
#endif
//end of the file

